package com.salt.common;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.lang.NonNull;

/**
 * 通用响应
 *
 * @author HaiBo Kuang
 * @version 0.0.1 2021/3/30
 * @since 0.0.1
 */

public class RestResponse<R> extends ResponseEntity<ResponseData> {

    public RestResponse(HttpStatus status) {
        super(status);
    }

    public static <T> ResponseEntity<ResponseData<T>> success() {
        return RestResponse.ok(ResponseData.success());
    }

    public static <T> ResponseEntity<ResponseData<T>> success(@NonNull T body) {
        return RestResponse.ok(ResponseData.successData(body));
    }

    public static <T> ResponseEntity<ResponseData<T>> fail(@NonNull String message) {
        return ResponseEntity.ok(ResponseData.failData(message));
    }

    public static <T> ResponseEntity<ResponseData<T>> fail(@NonNull ResponseStatus status) {
        return ResponseEntity.ok(ResponseData.failData(status));
    }

    public static <T> ResponseEntity<ResponseData<T>> fail(@NonNull ResponseStatus status, @NonNull String message) {
        return ResponseEntity.ok(ResponseData.failData(status, message));
    }

    public static <T> ResponseEntity<ResponseData<T>> fail(@NonNull ResponseStatus status,
                                                           @NonNull T body) {
        return ResponseEntity.ok(ResponseData.failData(status, body));
    }
}
